package com.xw.class03;

/**
 * @author: xw
 * @create: 2022/9/8 10:55
 * @description: 反转链表
 */
public class Code01_ReverseList {
    public static class Node<V>{
        public V value;
        public Node<V> next;

        public Node(V v){
            this.value  =v;
            next = null;
        }

    }

    /**
     * 双链表
     */
    public static class DoubleNode {
        public int value;
        public DoubleNode last;
        public DoubleNode next;

        public DoubleNode(int data) {
            value = data;
        }
    }

    public Node reverseList(Node head){
        Node pre = null;
        Node next = null;
        while(head != null){
            next = head.next;
            head.next = pre;
            pre = head;
            head = next;
        }
        return pre;
    }

    public DoubleNode reverseDoubleList(DoubleNode head){
        DoubleNode pre=null;
        DoubleNode next = null;
        while(null != head){
            next = head.next;
            head.next = pre;
            head.last = next;
            pre = head;
            head = next;
        }
        return pre;
    }
}
